using System;
using System.Collections.Generic;
using System.Text;
using Common.Shared.Design;

namespace Common.Shared.Xml.Wddx {
	[WddxRoot("string")]
	public class WddxCharArray : WddxString {
		private List<WddxChar> _chars;

		public WddxCharArray ( ) : base() {
			this.Chars = new List<WddxChar> ( );
		}

		public WddxCharArray ( char[] chars )
			: this ( ) {

			foreach ( char c in chars ) {
				this.Chars.Add ( new WddxChar ( c ) );
			}
			this.Value = new string ( chars );
		}

		public WddxCharArray ( string chars )
			: this ( chars.ToCharArray() ) {
		}

		public WddxCharArray ( List<WddxChar> chars )
			: this ( ) {
			this.Chars.AddRange ( chars );
			StringBuilder sb = new StringBuilder ( chars.Count );
			foreach ( WddxChar c in chars ) {
				sb.Append ( (char)c.Code );
			}
			this.Value = sb.ToString ( );
		}

		[WddxElement("char")]
		public List<WddxChar> Chars {
			get { return _chars; }
			set { _chars = value; }
		}

		[WddxIgnore]
		public override string Value {
			get {
				return base.Value;
			}
			set {
				base.Value = value;
			}
		}
	}
}
